package com.t174.car.controller;

import com.t174.car.dao.PurchaseDao;
import com.t174.car.entity.Purchase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/purchase")
@Scope("prototype")//默认到单例模式
public class PurchaseController {
    @Autowired
    private PurchaseDao purchaseDao;
    @RequestMapping("/querypu")//查询全部
    @ResponseBody
    public List<Purchase> querypu(){
        return purchaseDao.query();//查询全部
    }

    @RequestMapping("/save")//增加
    @ResponseBody
   public  int addsave(Purchase purchase){
        return  purchaseDao.addPur(purchase);
    }


    @RequestMapping("/del")//删除
    @ResponseBody
   public int del(String ids){
        String[] ss = ids.split("-");
        Integer[] myids = new Integer[ss.length] ;
        for(int i=0;i<ss.length;i++) {
            System.out.println(ss[i]);
            myids[i] = Integer.parseInt(ss[i]);
        }
        return  purchaseDao.del(myids);
   }

    @RequestMapping("/getPurchase")
    @ResponseBody
    public Purchase getPurchase(int id){

        return purchaseDao.puid(id);
    }

    @RequestMapping("/upPurchase")
    @ResponseBody
    public int upPurchase(Purchase purchase){
        return purchaseDao.udate(purchase);
    }

}
